﻿using MediatR;
using MyServer.Todo.Domain.Aggregates.TodoGroupAggregate;

namespace MyServer.Todo.ClientAPI.Application.CommandHandlers.TodoGroupHandlers
{
    public class CreateTodoGroupCommandHandler : IRequestHandler<CreateTodoGroupCommand, bool>
    {
        private readonly ITodoGroupRepository _todoGroupRepository;
        public CreateTodoGroupCommandHandler(ITodoGroupRepository todoGroupRepository)
        {
            _todoGroupRepository = todoGroupRepository??throw new ArgumentNullException(nameof(todoGroupRepository));
        }
        public async Task<bool> Handle(CreateTodoGroupCommand request, CancellationToken cancellationToken)
        {
            var todoGroup = new TodoGroup(request.UserId, request.TodoGroupName);
            _todoGroupRepository.Add(todoGroup);
            return await _todoGroupRepository.UnitOfWork.SaveEntitiesAsync();
        }
    }
}
